using System;
using System.Threading;
using Nau.Airplain.Common;

namespace Nau.Airplane.Networking
{
    public class TestNetworkListener : INetworkListener
    {
        public event EventHandler<MessageRecievedArgs> MessageRecieved;

        private CancellationToken _needCancel;

        public void Start(int port)
        {
            while (!_needCancel.IsCancellationRequested)
            {
                if (MessageRecieved != null)
                {
                    MessageRecieved(this, new MessageRecievedArgs
                                              {
                                                  MessageId = 0,
                                                  Text = string.Format("This is test message. Recieved at {0} and {1} seconds.", DateTime.Now.Minute, DateTime.Now.Second)
                                              });
                }

                Thread.Sleep(4000);
            }
        }

        public void Stop()
        {
            _needCancel = new CancellationToken(true);
        }
    }
}